<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<style type="text/css">
.balance{margin-left:20px;}
</style>
<script type="text/javascript" src="/static/customer.js"></script>
<script type="text/javascript">
function Account() {
	this.init=function(){
		defaultKeys('q').focus();	
		$('#button').click(function(){
			save();
		});
		$(document).keydown(function(event){
			var code = event.keyCode;
			if(KEY.ENTER==code) {
				//alert($('.button').is(":focus"));
			}
		});
	};
	function save() {
		$('.button').attr('disabled', 'disabled');
		var url_save = "/a/ajax/customer/account/save";
		var cid = $('#customerId').val();
		var addTime = $('#addTime').val();
		var money = $('#money').val();
		if(money==0) {
			alert('充值金额不能为0');
			return ;
		}
		$.ajax({
			url:url_save
			,type:'POST'
			,data:{cid:cid,money:money,addTime:addTime}
			,success:function(data){
				alert('操作成功！');
				var json = $.parseJSON(data);
				$('#balance').html(json.data.balance);
				$('.button').removeAttr('disabled');
				getRecord(cid);
			}
			,error:function(){
				alert('入帐失败，请检查参数重新尝试，或联系管理员！');
				$('.button').removeAttr('disabled');
			}
		});
	};
}
var account = new Account();
$(function(){
	account.init();
	$( "#addTime" ).datepicker({
		dateFormat:'yy-mm-dd'
	});
	// 客户自动搜索填充开始
	$("#q").autocomplete("/a/ajax/search/customer", {
		delay: 500
		, formatItem:function(item, index, total, query){
	    	return item.townName + " " + item.villageName + " " + item.customerName;
	    }
		, formatResult:function(item){
	    	return item.customerName;
	    }
		, dataType:'json'
		, parse:function(data) {
             return $.map(data, function(item) {
                     return {
                             data: item,
                             value: item.customerName,
                             result: item.customerName
                     }
        	}); // end map
		} // end parse

	}).result(function(event, data, formatted) {
		$(".customer").html('<a href="####" onclick=customer.showAccount("'+data.customerId+'")><strong>' 
							+ data.customerName +'</strong></a> ['
		                    + data.townName + data.villageName + '] '
		                    + ' ' + data.mobile);
		$(".balance").html('<span class="red">余额：<span id="balance">' + data.balance + '</span></span>');
		$('#customerId').val(data.customerId);
		$('.button').removeAttr('disabled');
	}); // end result
	//客户自动搜索填充结束
});
</script>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="form">
<div class="listnav">
</div>
<table>
<tbody>
<tr>
<th></th>
<td><input type="text" id="q" name="q" value="输入客户名称或客户唯一编号后回车查询"  title="输入客户名称或客户唯一编号后回车查询"/></td>
</tr>
<tr>
<th>帐户信息</th>
<td>
<span class="customer"></span>
<span class="balance"></span>
</td>
</tr>
<tr>
<th>充值日期</th>
<td>
<input type="text" id="addTime" name="addTime" value="${addDate}" class=hasDatepicker" />
</td>
</tr>
<tr>
<th>充值金额</th>
<td>
<input type="text" id="money" name="money" value="0" />
</td>
</tr>
<tr>
<th></th>
<td>
<input type="hidden" name="customerId" id="customerId" value="" />
<input type="button" name="button" id="button" value="<fmt:message key="message.save.sure"/>" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="sidebarMenu">
<ul>
<li><a href="/a/customer/">返回客户列表</a></li>
</ul>
</div>
<div class="sidebar">
<div class="prop-item">
</div>
</div>
<!--  -->
<div class="list">

</div>
</div>
</div>
</body>
</html>